﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.SilverlightMediaFramework.Player;

namespace SMF.HowTo.Sample
{
    [TemplatePart(Name = "btnToggle", Type = typeof(ButtonBase))]
    [TemplateVisualState(Name = "ShowingCustomContent", GroupName = "CustomContent")]
    [TemplateVisualState(Name = "HidingCustomContent", GroupName = "CustomContent")]
    public class CustomPlayer : Player
    {
        private bool _showingCustomContent = false;
        private ButtonBase _btnToggle;

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _btnToggle = GetTemplateChild("btnToggle") as ButtonBase;
            if (_btnToggle != null)
            {
                _btnToggle.Click += new RoutedEventHandler(_btnToggle_Click);
            }
        }

        void _btnToggle_Click(object sender, RoutedEventArgs e)
        {
            _showingCustomContent = !_showingCustomContent;
            if (_showingCustomContent)
            {
                VisualStateManager.GoToState(this, "ShowingCustomContent", true);
            }
            else
            {
                VisualStateManager.GoToState(this, "HidingCustomContent", true);
            }
        }
    }
}
